﻿@{
    Layout = "";
}
<style>
    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 45% !important;
    }
</style>
<div ng-controller="LevelDetailController">
    <div class="container-fluid" ng-show="!selectProduct" id="AgentInfoUpdateMainViewPanel">
        <div class="row">
            <div class="col-md-12">
                <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal">
                    <!-- START panel-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading,'': isLoading }">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>等级详情</legend>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">等级名称</label>
                                    <div class="col-sm-4">
                                        <input maxlength="128" type="text" name="LevelName" required="" ng-model="model.LevelName" class="form-control" />
                                        <span ng-show="validateInput('LevelName', 'required')" class="text-danger">请输入等级名称</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">消费额度</label>
                                    <div class="col-sm-4">
                                        <input maxlength="50" type="number" name="Amount" required="" ng-model="model.Amount" class="form-control"  />
                                        <span ng-show="validateInput('Amount', 'required')" class="text-danger">请输入消费额度</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">折扣率(%)(会员购买的价格就是商品价格*折扣率，0为不打折)</label>
                                    <div class="col-sm-4">
                                        <input maxlength="50" type="number" name="Discount" required="" ng-model="model.Discount" class="form-control" />
                                        <span ng-show="validateInput('Discount', 'required')" class="text-danger">请输入折扣率</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">签到积分</label>
                                    <div class="col-sm-4">
                                        <input maxlength="50" type="number" name="SignPoint" required="" ng-model="model.SignPoint" class="form-control" />
                                        <span ng-show="validateInput('SignPoint', 'required')" class="text-danger">请输入签到积分</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">会员日（积分倍数）</label>
                                    <div class="col-sm-4">
                                        <input maxlength="50" type="number" name="MemberDayTimes" required="" ng-model="model.MemberDayTimes" class="form-control" />
                                        <span ng-show="validateInput('MemberDayTimes', 'required')" class="text-danger">请输入会员日（积分倍数）</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">订单返积分比例</label>
                                    <div class="col-sm-4">
                                        <input maxlength="50" type="number" name="OrderPoint" required="" ng-model="model.OrderPoint" class="form-control" />
                                        <span ng-show="validateInput('OrderPoint', 'required')" class="text-danger">请输入订单返积分比例</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">说明</label>
                                    <div class="col-sm-4">
                                        <input maxlength="200" type="text" name="Explain" required="" ng-model="model.Explain" class="form-control" />
                                        <span ng-show="validateInput('Explain', 'required')" class="text-danger">请输入签到积分</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                        <div class="panel-footer text-right">
                            <button type="button" class="btn btn-warning" ng-click="cancel()">返回列表</button>
                            <button type="button" class="btn btn-primary" ng-click="save()">保存</button>
                        </div>
                    </div>
                    <!-- END panel-->
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    App.controller('LevelDetailController', ["$scope", "$state", "$http", "$stateParams", "Notify", "$filter",
        function ($scope, $state, $http, $stateParams, Notify, $filter) {
            'use strict';
            $scope.isLoading = true;
            $scope.validateInput = function (name, type) {
                var input = $scope.formValidate[name];
                return (input.$dirty || $scope.submitted) && input.$error[type];
            };



            //数据初始化
            $http.post("/Member/GetLevelInfo", { Id: $stateParams.id }).then(function (response) {
                $scope.model = response.data;
                if (!$scope.model) {
                    Notify.alert("该等级不存在", { status: 'warning' });
                    $state.go('app.levels');
                    $scope.model = {};
                }
                $scope.isLoading = false;
            });

            // 提交
            $scope.save = function () {
                $scope.submitted = true;
                $scope.isLoading = true;
                if ($scope.formValidate.$valid) {
                    $http.post("/Member/EditLevel", { model: $scope.model }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success' });
                            $state.go("app.levels");
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning' });
                            $scope.isLoading = false;
                        }
                    });
                } else {
                    $scope.isLoading = false;
                }
            };

            //返回列表
            $scope.cancel = function () {
                $state.go('app.levels');
            }
        }]);
</script>
